//
//  ToastTools.m
//  MTime
//
//  Created by imac on 2017/8/14.
//  Copyright © 2017年 imac. All rights reserved.
//

#import "ToastTools.h"



@interface ToastTools()

@property (nonatomic, strong) QMUIModalPresentationViewController *alertViewController;

@end

@implementation ToastTools

#pragma mark - 弹窗式TF
//+ (void)showDialogTFWithTitle:(NSString *)title tfPlaceholder:(NSString *)placeholder maxTextLength:(NSInteger)maxTextLength confirmCallback:(TFConfirmBlock)callback {
//    if (maxTextLength == 0) {
//        maxTextLength = 20;
//    }
//    QMUIDialogTextFieldViewController *dialogTFVC = [[QMUIDialogTextFieldViewController alloc] init];
//    [dialogTFVC addCancelButtonWithText:@"取消" block:nil];
//    dialogTFVC.titleLabelTextColor = [UIColor baseColor];
//    dialogTFVC.buttonTitleAttributes = @{NSForegroundColorAttributeName:[UIColor baseColor]};
//    dialogTFVC.title = title;
//    dialogTFVC.textFields
//    dialogTFVC.textField.placeholder = placeholder;
//    dialogTFVC.textField.maximumTextLength = maxTextLength;
//    //    MinesTimeWeakSelf
//    [dialogTFVC addSubmitButtonWithText:@"确认" block:^(QMUIDialogViewController *dialogViewController) {
//        if ([dialogViewController isKindOfClass:[QMUIDialogTextFieldViewController class]]) {
//            QMUIDialogTextFieldViewController *dialogTF = (QMUIDialogTextFieldViewController *)dialogViewController;
//            [dialogTF.textField resignFirstResponder];
//            if (callback) {
//                callback(dialogTF.textField.text);
//                [dialogTF hide];
//            }
//        }
//    }];
//    [dialogTFVC show];
//}

//+ (void)showInputTextFieldControllerWithPlaceholderLabel:(NSString *)label keyboardType:(UIKeyboardType)keyboardType cancelButton:(CancelButtonBlock)cancel confirmButton:(ConfirmButtonBlock)confirm {
//    
//    QMUIDialogTextFieldViewController *inputTFVC = [[QMUIDialogTextFieldViewController alloc] init];
////    inputTFVC.buttonTitleAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:17] ,NSForegroundColorAttributeName:[UIColor cyanColor]};
//    UIView *view = [[UIView alloc]init];
//    view.backgroundColor = [UIColor cyanColor];
//    inputTFVC.contentView = view;
//    inputTFVC.textField.placeholder = label;
//    inputTFVC.textField.keyboardType = keyboardType;
//   __block QMUITextField *tf = inputTFVC.textField;
//    
//    [inputTFVC addCancelButtonWithText:@"取消" block:^(QMUIDialogViewController *dialogViewController) {
//        if (cancel) {
//            cancel();
//        }
//    }];
////
//    [inputTFVC addSubmitButtonWithText:@"确定" block:^(QMUIDialogViewController *dialogViewController) {
//        [dialogViewController hide];
//        if (confirm) {
//            confirm(tf.text);
//        }
//    }];
//    
//    [inputTFVC show];
//}

#pragma mark - 无标题弹窗
+ (void)showDialogWithContent:(NSString *)content cancelAction:(void (^)(void))cancelAction submitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(97))];
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0);
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = 0;
    dialogViewController.footerViewHeight = kFLOAT(45);
    
    [dialogViewController addCancelButtonWithText:@"" block:^(QMUIDialogViewController *dialogViewController) {
        if (cancelAction) {
            cancelAction();
        }
    }];
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = UIFontBoldMake(17);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置取消按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#999999"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.cancelButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    //设置确定按钮
    attri = [[NSMutableAttributedString alloc] initWithString:@"确定" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(97) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    UIImageView *col = [[UIImageView alloc] initWithFrame:CGRectMake(kFLOAT(271) / 2.0, 0, 1, kFLOAT(45))];
    col.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
    [dialogViewController.cancelButton addSubview:col];
}

#pragma mark - 无标题弹窗，自定义按钮文字
+ (void)showCustomeDialogWithContent:(NSString *)content cancelTitle:(NSString *)cancelTitle comfirmTitle:(NSString *)comfirmTitle cancelAction:(void (^)(void))cancelAction submitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(97))];
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0);
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = 0;
    dialogViewController.footerViewHeight = kFLOAT(45);
    
    [dialogViewController addCancelButtonWithText:@"" block:^(QMUIDialogViewController *dialogViewController) {
        if (cancelAction) {
            cancelAction();
        }
    }];
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = UIFontBoldMake(17);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置取消按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:cancelTitle attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#999999"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.cancelButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    //设置确定按钮
    attri = [[NSMutableAttributedString alloc] initWithString:comfirmTitle attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(97) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    UIImageView *col = [[UIImageView alloc] initWithFrame:CGRectMake(kFLOAT(271) / 2.0, 0, 1, kFLOAT(45))];
    col.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
    [dialogViewController.cancelButton addSubview:col];
}

#pragma mark - 无标题，只有确定按钮的弹窗
+ (void)showConfirmDialogWithContent:(NSString *)content submitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(97))];
    
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.numberOfLines = 0;
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0);
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = 0;
    dialogViewController.footerViewHeight = kFLOAT(45);
    
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = UIFontBoldMake(17);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置确定按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"确认" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(97) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
}



#pragma mark - 有标题弹窗
+ (void)showDialogWithTitle:(NSString *)title content:(NSString *)content submitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    dialogViewController.title = title;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(48))];
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0 - kFLOAT(10));
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = kFLOAT(49);
    dialogViewController.footerViewHeight = kFLOAT(45);
    
    [dialogViewController addCancelButtonWithText:@"" block:nil];
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = kFONT(17);
    dialogViewController.titleView.titleEdgeInsets = UIEdgeInsetsMake(17, 0, 0, 0);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置取消按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#999999"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.cancelButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    //设置确定按钮
    attri = [[NSMutableAttributedString alloc] initWithString:@"确认" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(48) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    UIImageView *col = [[UIImageView alloc] initWithFrame:CGRectMake(kFLOAT(271) / 2.0, 0, 1, kFLOAT(45))];
    col.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
    [dialogViewController.cancelButton addSubview:col];
}

#pragma mark - 有标题 只有确定按钮的弹窗
+ (void)showDialogWithTitle:(NSString *)title content:(NSString *)content onlySubmitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    dialogViewController.title = title;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(48))];
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0 - kFLOAT(10));
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = kFLOAT(57);
    dialogViewController.footerViewHeight = kFLOAT(45);
    
//    [dialogViewController addCancelButtonWithText:@"" block:nil];
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = kFONT(17);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置取消按钮
//    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSForegroundColorAttributeName: kCOLOR_HEX(0x999999), NSFontAttributeName: kFONT(14)}];
//    [dialogViewController.cancelButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    //设置确定按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"确认" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(48) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
}

#pragma mark - 有标题弹窗 自定义按钮文字
+ (void)showDialogWithTitle:(NSString *)title content:(NSString *)content cancelTitle:(NSString *)cancelTitle submitTitle:(NSString *)submitTitle cancelAction:(void (^)(void))cancelAction submitAction:(void (^)(void))submitAction {
    QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
    dialogViewController.title = title;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kFLOAT(271), kFLOAT(48))];
    contentView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] qmui_initWithFont:kFONT(15) textColor:[UIColor colorWithHex:@"#666666"]];
    label.text = content;
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetWidth(contentView.bounds) / 2.0, CGRectGetHeight(contentView.bounds) / 2.0 - kFLOAT(10));
    [contentView addSubview:label];
    dialogViewController.contentView = contentView;
    dialogViewController.headerViewHeight = kFLOAT(49);
    dialogViewController.footerViewHeight = kFLOAT(45);
    
    [dialogViewController addCancelButtonWithText:@"" block:^(QMUIDialogViewController *dialogViewController) {
        if (cancelAction) {
            cancelAction();
        }
    }];
    [dialogViewController addSubmitButtonWithText:@"" block:^(QMUIDialogViewController *aDialogViewController) {
        [aDialogViewController hide];
        if (submitAction) {
            submitAction();
        }
    }];
    
    // 自定义样式
    dialogViewController.headerViewBackgroundColor = [UIColor whiteColor];
    dialogViewController.headerSeparatorColor = UIColorClear;
    dialogViewController.titleTintColor = [UIColor colorWithHex:@"#333333"];
    dialogViewController.titleView.horizontalTitleFont = kFONT(17);
    dialogViewController.titleView.titleEdgeInsets = UIEdgeInsetsMake(17, 0, 0, 0);
    dialogViewController.buttonHighlightedBackgroundColor = [dialogViewController.headerViewBackgroundColor qmui_colorWithAlphaAddedToWhite:.3];
    //设置取消按钮
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:cancelTitle attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#999999"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.cancelButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    //设置确定按钮
    attri = [[NSMutableAttributedString alloc] initWithString:submitTitle attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHex:@"#4990E2"], NSFontAttributeName: kFONT(14)}];
    [dialogViewController.submitButton setAttributedTitle:attri forState:(UIControlStateNormal)];
    [dialogViewController show];
    //添加分割线
    UIImageView *row = [[UIImageView alloc] initWithFrame:CGRectMake(0, kFLOAT(48) - 1, kFLOAT(271), 1)];
    row.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    UIImageView *col = [[UIImageView alloc] initWithFrame:CGRectMake(kFLOAT(271) / 2.0, 0, 1, kFLOAT(45))];
    col.backgroundColor = [[UIColor colorWithHex:@"#DCDCDC"] colorWithAlphaComponent:0.75];
    
    [contentView addSubview:row];
    [dialogViewController.cancelButton addSubview:col];
}

#pragma mark - 从底部向上弹窗
- (void)showDialogWithTitleView:(UIView *)titleView optionViewOne:(UIView *)optionViewOne optionViewTwo:(UIView *)optionViewTwo {
    //禁止全局点击事件
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    //布局视图
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.0f];
    //有标题视图时的布局
    if (titleView) {
        //标题视图
        titleView.frame = CGRectMake(0, 0, titleView.frame.size.width, titleView.frame.size.height);
        [contentView addSubview:titleView];
        //分割线
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0,(titleView.frame.size.height + titleView.frame.origin.y), SCREEN_WIDTH, 1)];
        line.backgroundColor = [UIColor backgroundColor];
        [contentView addSubview:line];
        //选项视图1
        optionViewOne.frame = CGRectMake(0, (line.frame.size.height + line.frame.origin.y), optionViewOne.frame.size.width, optionViewOne.frame.size.height);
        [contentView addSubview:optionViewOne];
        //选项视图2
        optionViewTwo.frame = CGRectMake(0, (optionViewOne.frame.size.height + optionViewOne.frame.origin.y) + kFLOAT(5), optionViewTwo.frame.size.width, optionViewTwo.frame.size.height);
        [contentView addSubview:optionViewTwo];
        //frame
        contentView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, titleView.frame.size.height + optionViewOne.frame.size.height + optionViewTwo.frame.size.height + kFLOAT(5) + 1);
    }
    //没有标题视图时的布局
    else {
        //选项视图1
        optionViewOne.frame = CGRectMake(0, 0, optionViewOne.frame.size.width, optionViewOne.frame.size.height);
        [contentView addSubview:optionViewOne];
        //选项视图2
        optionViewTwo.frame = CGRectMake(0, (optionViewOne.frame.size.height + optionViewOne.frame.origin.y) + kFLOAT(5), optionViewTwo.frame.size.width, optionViewTwo.frame.size.height);
        [contentView addSubview:optionViewTwo];
        //frame
        contentView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, optionViewOne.frame.size.height + optionViewTwo.frame.size.height + kFLOAT(5));
    }
    
    self.alertViewController = [[QMUIModalPresentationViewController alloc] init];
    self.alertViewController.contentView = contentView;
    
    self.alertViewController.layoutBlock = ^(CGRect containerBounds, CGFloat keyboardHeight, CGRect contentViewDefaultFrame) {
        contentView.frame = CGRectMake(0, SCREEN_HEIGHT  - contentView.frame.size.height, SCREEN_WIDTH, contentView.frame.size.height);
    };
    self.alertViewController.showingAnimation = ^(UIView *dimmingView, CGRect containerBounds, CGFloat keyboardHeight, CGRect contentViewFrame, void(^completion)(BOOL finished)) {
        contentView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, contentView.frame.size.height);
        dimmingView.alpha = 0;
        [UIView animateWithDuration:.3 delay:0.0 options:QMUIViewAnimationOptionsCurveOut animations:^{
            dimmingView.alpha = 1;
            contentView.frame = contentViewFrame;
        } completion:^(BOOL finished) {
            // 记住一定要在适当的时机调用completion()
            if (completion) {
                completion(finished);
            }
            //动画执行完成后，开启全局的点击事件
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];
        }];
    };
    self.alertViewController.hidingAnimation = ^(UIView *dimmingView, CGRect containerBounds, CGFloat keyboardHeight, void(^completion)(BOOL finished)) {
        [UIView animateWithDuration:.3 delay:0.0 options:QMUIViewAnimationOptionsCurveOut animations:^{
            dimmingView.alpha = 0.0;
            contentView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, contentView.frame.size.height);
        } completion:^(BOOL finished) {
            // 记住一定要在适当的时机调用completion()
            if (completion) {
                completion(finished);
            }
        }];
    };
    //设置窗口视图优先级
    QMUICMI.windowLevelQMUIAlertView = UIWindowLevelNormal;
    [self.alertViewController showWithAnimated:YES completion:nil];
}

#pragma mark - 收起弹窗
- (void)hideViewWithAnimated:(BOOL)animated completion:(void(^)(void))completion {
    [self.alertViewController hideWithAnimated:animated completion:^(BOOL finished) {
        if (completion) {
            completion();
        }
    }];
}
/*
#pragma mark - 调用地区选择器
+ (void)showAreaSelectorWithSelectionMode:(AreaSelectionMode)mode dataSourceArray:(NSArray *)array callback:(RegionSelectionCallback)callback {
    //点击筛选按钮后，禁止全局的点击事件
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    //地区选择控制器
    AreaSelectionViewController *areaSelector = [[AreaSelectionViewController alloc] initWithSelectionMode:mode  dataSourceArray:array callback:callback];
    //弹窗
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
    NSLog(@"%@", modalViewController);
    modalViewController.contentView = areaSelector.view;
    //关闭窗口
    __weak typeof(modalViewController) weakModalViewController = modalViewController;
    [areaSelector.closeButton buttonWithBlock:^(UIButton *button) {
        [weakModalViewController hideWithAnimated:YES completion:nil];
    }];
    //布局block
    modalViewController.layoutBlock = ^(CGRect containerBounds, CGFloat keyboardHeight, CGRect contentViewDefaultFrame) {
        areaSelector.view.frame = CGRectMake(0, kFLOAT(361), SCREEN_WIDTH, SCREEN_HEIGHT - kFLOAT(361));
    };
    //显示block
    modalViewController.showingAnimation = ^(UIView *dimmingView, CGRect containerBounds, CGFloat keyboardHeight, CGRect contentViewFrame, void(^completion)(BOOL finished)) {
        areaSelector.view.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - kFLOAT(361));
        dimmingView.alpha = 0;
        [UIView animateWithDuration:.3 delay:0.0 options:QMUIViewAnimationOptionsCurveOut animations:^{
            dimmingView.alpha = 1;
            areaSelector.view.frame = contentViewFrame;
        } completion:^(BOOL finished) {
            // 记住一定要在适当的时机调用completion()
            if (completion) {
                completion(finished);
            }
            //动画执行完成后，开启全局的点击事件
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];
        }];
    };
    //block
    modalViewController.hidingAnimation = ^(UIView *dimmingView, CGRect containerBounds, CGFloat keyboardHeight, void(^completion)(BOOL finished)) {
        [UIView animateWithDuration:.3 delay:0.0 options:QMUIViewAnimationOptionsCurveOut animations:^{
            dimmingView.alpha = 0.0;
            areaSelector.view.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - kFLOAT(361));
        } completion:^(BOOL finished) {
            // 记住一定要在适当的时机调用completion()
            if (completion) {
                completion(finished);
            }
        }];
    };
    //设置窗口视图优先级
    QMUICMI.windowLevelQMUIAlertView = UIWindowLevelNormal;
    [modalViewController showWithAnimated:YES completion:nil];
}
*/
@end
